import {useField, useForm} from "vee-validate";
import * as yup from "yup";
import {computed, watch} from "vue";
import {useStore} from "vuex";
import {useRouter} from "vue-router";

export default function useRequestForm(fn){

    const store = useStore();

    const router = useRouter();

    const {handleSubmit, isSubmitting, submitCount} = useForm({
        initialValues: {
            status: 'active',
        }
    });

    const {value: FIO, errorMessage: fioError, handleBlur: fioBlur} = useField(
        'FIO',
        yup
            .string()
            .trim()
            .required('Введите ФИО')
    );

    const {value: phone, errorMessage: pError, handleBlur: pBlur} = useField(
        'phone',
        yup
            .string()
            .trim()
            .required('Введите Телефон')
    );

    const {value: amount, errorMessage: aError, handleBlur: aBlur} = useField(
        'amount',
        yup.number()
            .required('Введите сумму')
            .min(0, 'Сумма не может быть меньше 0')
    );

    const {value: status} = useField('status',);

    const onSubmit = handleSubmit(fn);


    return{
        FIO, fioError, fioBlur,
        phone, pError, pBlur,
        amount, aError, aBlur,
        status,
        onSubmit, isSubmitting
    }
}
